Skip to content

rivertest: enable metadata assertions#1137

Open
bgentry wants to merge 1 commit intomasterfrom
bg/rivertest-metadata
Open

rivertest: enable metadata assertions#1137
bgentry wants to merge 1 commit intomasterfrom
bg/rivertest-metadata

Conversation

@bgentry
Copy link
Contributor

@bgentry bgentry commented Jan 30, 2026

This enables basic assertions against metadata in rivertest.RequireX methods. The approach here isn't anything special: it allows a map[string]any to be specified and considers it a failure if all keys & values in it are not also in the metadata.

This should make it possible to build workflow-related assertions and other metadata assertions much more easily.

@bgentry bgentry requested a review from brandur January 30, 2026 15:13
This enables basic assertions against metadata in `rivertest.RequireX`
methods. The approach here isn't anything special: it allows a
`map[string]any` to be specified and considers it a failure if all keys
& values in it are not also in the metadata.

This should make it possible to build workflow-related assertions and
other metadata assertions much more easily.
@bgentry bgentry force-pushed the bg/rivertest-metadata branch from 05ffe68 to 9e07519 Compare January 30, 2026 15:13
Copy link
Contributor

@brandur brandur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, my fault on the delay here.

Just want to run one alt by you, but generally looks fine.

// ignored.
//
// No assertion is made if left nil or empty.
Metadata map[string]any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just related to our convo last weekend, wanted to quickly get your thoughts on allowing people to do something like specify an exact match versus partial match.

If this became:

	Metadata MetadataMatcher

And you had something like:

type MetadataMatcher interface {
	CheckMatch(t testingT, actualBytes []byte, requireNotInserted bool) (bool, []string)
}

type metadataContainsMatcher struct {
	expected map[string]any
}

// MetadataContains checks that the given key-value pairs are present in job
// metadata, ignoring any extra keys that may also be there.
func MetadataContains(expected map[string]any) metadataContainsMatcher {
	return metadataContainsMatcher{expected: expected}
}

type metadataExactlyMatcher struct {
	expected map[string]any
}

// MetadataExactly checks that the given key-value pairs are present in job
// metadata, and that no extra keys are present.
func MetadataExactly(expected map[string]any) metadataExactlyMatcher {
	return metadataExactlyMatcher{expected: expected}
}

You get a pretty clean check that's a bit more readable than what's in here right now like:

			opts.Metadata = MetadataContains(map[string]any{
				"key": "value",
			})

The downside is that sometimes these interface-based checks can be a little hard to figure out how to use.

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants